home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Everything / Bars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  14.3 KB  |  528 lines  |  [TEXT/CWIE]

  1. /* Bars.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "ControlUtils.h"
  23. #include "Dispatcher.h"
  24. #include "DDocData.h"
  25. #include "EverythingEngine.h"
  26. #include "EverythingDoc.h"
  27. #include "Bars.h"
  28.  
  29.  
  30. static    EverythingEngine*      GetEngine    (Bars*    self);
  31.  
  32. static    void    DoUndo        (Bars*    self);
  33. static    void    DoCut        (Bars*    self);
  34. static    void    DoCopy        (Bars*    self);
  35. static    void    DoPaste        (Bars*    self);
  36. static    void    DoClear        (Bars*    self);
  37. static    void    DoSelectAll        (Bars*    self);
  38. static    void    DoShowClipboard    (Bars*    self);
  39.  
  40.  
  41. //----------
  42. Bars*        NewBars ()
  43. {
  44.     Bars*        window;
  45.  
  46.     window = (Bars*)malloc (sizeof (Bars));
  47.     Bars_Init (window);
  48.     SetClassID (window, classBars);
  49.  
  50.     return window;
  51. }
  52.  
  53. //----------
  54. void    DeleteBars (
  55.     Bars*        window)
  56. {
  57.     Bars_Free (window);
  58.     free (window);
  59. }
  60.  
  61. //----------
  62. void    Bars_Create (
  63.     AMDoc*            inDoc,
  64.     DDocData*        inData)
  65. {
  66.     Bars*        winObj = NewBars ();
  67.  
  68.     if (winObj != nil) {
  69.         Bars_Open (winObj, inDoc, inData);
  70.     }
  71. }
  72.  
  73. //----------
  74. void    Bars_Init (
  75.     Bars*        self)
  76. {
  77. }
  78.  
  79. //----------
  80. void    Bars_Free (
  81.     Bars*        self)
  82. {
  83. }
  84.  
  85. //----------
  86. EverythingEngine*    GetEngine (
  87.     Bars*        self)
  88. {
  89.     return (EverythingEngine*) self->super.mDoc->mEngine;
  90. }
  91.  
  92. /*----------*/
  93. void    Bars_Open (
  94.     Bars*        self,
  95.     AMDoc*            inDoc,
  96.     DDocData*        inData)
  97. {
  98.     WindowPtr        window;
  99.     Handle            wftb;
  100.  
  101.     self->super.mDoc = inDoc;
  102.     self->mData = inData;
  103.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  104.  
  105.     window = GetNewCWindow (WIND_Bars, nil, (WindowPtr) -1L);
  106.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  107.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  108.     }
  109.     self->super.mWindow = window;
  110.     ((EverythingDoc*)self->super.mDoc)->mBarsPtr = window;
  111.  
  112.     SetWindowKind (window, 'AM');
  113.     SetWRefCon (window, (long) self);
  114.     SetPort (window);
  115.     SetInfo (window);
  116.  
  117.     wftb = GetResource ('Wftb', WIND_Bars);
  118.  
  119.     CreateRootControl (window, &self->super.mRootControl);
  120.  
  121.     self->super.vScroll = nil;
  122.     self->super.hScroll = nil;
  123.  
  124.  
  125.     self->mBarsHandle = GetNewControl (CNTL_Bars, window);
  126.     SetWindowItemFont (self->mBarsHandle, wftb, 1);
  127.     SetControlValue (self->mBarsHandle, GetBars (self->mData));
  128.     SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  129.  
  130.     self->mScrollBarsHandle = GetNewControl (CNTL_ScrollBars, window);
  131.     EmbedControl (self->mScrollBarsHandle, self->mBarsHandle);
  132.     SetWindowItemFont (self->mScrollBarsHandle, wftb, 2);
  133.  
  134.     self->mStandard4Handle = GetNewControl (CNTL_Standard4, window);
  135.     EmbedControl (self->mStandard4Handle, self->mScrollBarsHandle);
  136.     SetWindowItemFont (self->mStandard4Handle, wftb, 3);
  137.     SetControlValue (self->mStandard4Handle, GetStandard2 (self->mData));
  138.  
  139.     self->mGraphic4Handle = GetNewControl (CNTL_Graphic4, window);
  140.     EmbedControl (self->mGraphic4Handle, self->mScrollBarsHandle);
  141.     SetWindowItemFont (self->mGraphic4Handle, wftb, 4);
  142.     SetControlValue (self->mGraphic4Handle, GetGraphic2 (self->mData));
  143.  
  144.     self->mSliderHandle = GetNewControl (CNTL_Slider, window);
  145.     EmbedControl (self->mSliderHandle, self->mScrollBarsHandle);
  146.     SetWindowItemFont (self->mSliderHandle, wftb, 5);
  147.     SetControlValue (self->mSliderHandle, GetSlider (self->mData));
  148.  
  149.     self->mTickMarksHandle = GetNewControl (CNTL_TickMarks, window);
  150.     EmbedControl (self->mTickMarksHandle, self->mScrollBarsHandle);
  151.     SetWindowItemFont (self->mTickMarksHandle, wftb, 6);
  152.     SetControlValue (self->mTickMarksHandle, GetTickMarks (self->mData));
  153.  
  154.     self->mNonDirectionalHandle = GetNewControl (CNTL_NonDirectional, window);
  155.     EmbedControl (self->mNonDirectionalHandle, self->mScrollBarsHandle);
  156.     SetWindowItemFont (self->mNonDirectionalHandle, wftb, 7);
  157.     SetControlValue (self->mNonDirectionalHandle, GetNonDirectional (self->mData));
  158.  
  159.     self->mLittleArrowsHandle = GetNewControl (CNTL_LittleArrows, window);
  160.     EmbedControl (self->mLittleArrowsHandle, self->mScrollBarsHandle);
  161.     SetWindowItemFont (self->mLittleArrowsHandle, wftb, 8);
  162.     SetControlValue (self->mLittleArrowsHandle, GetLittleArrows (self->mData));
  163.  
  164.     self->mSpinnerHandle = GetNewControl (CNTL_Spinner, window);
  165.     EmbedControl (self->mSpinnerHandle, self->mScrollBarsHandle);
  166.     SetWindowItemFont (self->mSpinnerHandle, wftb, 9);
  167.     SetControlValue (self->mSpinnerHandle, GetSpinner (self->mData));
  168.  
  169.     self->mVolumeControlHandle = GetNewControl (CNTL_VolumeControl, window);
  170.     EmbedControl (self->mVolumeControlHandle, self->mScrollBarsHandle);
  171.     SetWindowItemFont (self->mVolumeControlHandle, wftb, 10);
  172.     SetControlValue (self->mVolumeControlHandle, GetVolumeControl (self->mData));
  173.  
  174.     self->mJimSSliderHandle = GetNewControl (CNTL_JimSSlider, window);
  175.     EmbedControl (self->mJimSSliderHandle, self->mScrollBarsHandle);
  176.     SetWindowItemFont (self->mJimSSliderHandle, wftb, 11);
  177.     SetControlValue (self->mJimSSliderHandle, GetJimSSlider (self->mData));
  178.  
  179.     self->mProgressBarsHandle = GetNewControl (CNTL_ProgressBars, window);
  180.     EmbedControl (self->mProgressBarsHandle, self->mBarsHandle);
  181.     SetWindowItemFont (self->mProgressBarsHandle, wftb, 12);
  182.  
  183.     self->mStandard5Handle = GetNewControl (CNTL_Standard5, window);
  184.     EmbedControl (self->mStandard5Handle, self->mProgressBarsHandle);
  185.     SetWindowItemFont (self->mStandard5Handle, wftb, 13);
  186.     SetControlValue (self->mStandard5Handle, GetStandard3 (self->mData));
  187.  
  188.     self->mIndeterminateHandle = GetNewControl (CNTL_Indeterminate, window);
  189.     EmbedControl (self->mIndeterminateHandle, self->mProgressBarsHandle);
  190.     SetWindowItemFont (self->mIndeterminateHandle, wftb, 14);
  191.     SetControlValue (self->mIndeterminateHandle, GetIndeterminate (self->mData));
  192.     SetIndeterminateState (self->mIndeterminateHandle, true);
  193.  
  194.     self->mChasingArrowsHandle = GetNewControl (CNTL_ChasingArrows, window);
  195.     EmbedControl (self->mChasingArrowsHandle, self->mProgressBarsHandle);
  196.     SetWindowItemFont (self->mChasingArrowsHandle, wftb, 15);
  197.     SetControlValue (self->mChasingArrowsHandle, GetChasingArrows (self->mData));
  198.  
  199.     self->mRectangleHandle = GetNewControl (CNTL_Rectangle, window);
  200.     EmbedControl (self->mRectangleHandle, self->mProgressBarsHandle);
  201.     SetWindowItemFont (self->mRectangleHandle, wftb, 16);
  202.     SetControlValue (self->mRectangleHandle, GetRectangle (self->mData));
  203.  
  204.     self->mRoundRectHandle = GetNewControl (CNTL_RoundRect, window);
  205.     EmbedControl (self->mRoundRectHandle, self->mProgressBarsHandle);
  206.     SetWindowItemFont (self->mRoundRectHandle, wftb, 17);
  207.     SetControlValue (self->mRoundRectHandle, GetRoundRect (self->mData));
  208.  
  209.     self->mBarberPoleHandle = GetNewControl (CNTL_BarberPole, window);
  210.     EmbedControl (self->mBarberPoleHandle, self->mProgressBarsHandle);
  211.     SetWindowItemFont (self->mBarberPoleHandle, wftb, 18);
  212.     SetControlValue (self->mBarberPoleHandle, GetBarberPole (self->mData));
  213.  
  214.     self->mRoundBarberHandle = GetNewControl (CNTL_RoundBarber, window);
  215.     EmbedControl (self->mRoundBarberHandle, self->mProgressBarsHandle);
  216.     SetWindowItemFont (self->mRoundBarberHandle, wftb, 19);
  217.     SetControlValue (self->mRoundBarberHandle, GetRoundBarber (self->mData));
  218.  
  219.     SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  220.  
  221.     AdvanceKeyboardFocus (window);
  222.  
  223.     ShowWindow (window);
  224. }
  225.  
  226. /*----------*/
  227. void    Bars_Close (
  228.     Bars*        self)
  229. {
  230.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  231.  
  232.     ((EverythingDoc*)self->super.mDoc)->mBarsPtr = nil;
  233.     SetInfo (nil);
  234.     HideWindow (self->super.mWindow);
  235.     DisposeWindow (self->super.mWindow);
  236.  
  237.     DeleteBars (self);
  238. }
  239.  
  240. /*----------*/
  241. void    Bars_Track (
  242.     Bars*        self,
  243.     ControlHandle    whichControl,
  244.     short            whichPart,
  245.     Point            where)
  246. {
  247.     Rect            bounds;
  248.     short            newValue;
  249.  
  250.     if (whichControl == self->mBarsHandle) {
  251.         if (TrackClick (self->mBarsHandle, where) != 0) {
  252.             SetBars (self->mData, GetControlValue (self->mBarsHandle));
  253.         }
  254.     }
  255.     if (whichControl == self->mStandard4Handle) {
  256.         HandleControlClick (self->mStandard4Handle, where, curEvent.modifiers, nil);
  257.         SetStandard2 (self->mData, GetControlValue (self->mStandard4Handle));
  258.     }
  259.     if (whichControl == self->mGraphic4Handle) {
  260.         HandleControlClick (self->mGraphic4Handle, where, curEvent.modifiers, nil);
  261.         SetGraphic2 (self->mData, GetControlValue (self->mGraphic4Handle));
  262.     }
  263.     if (whichControl == self->mSliderHandle) {
  264.         HandleControlClick (self->mSliderHandle, where, curEvent.modifiers, nil);
  265.         SetSlider (self->mData, GetControlValue (self->mSliderHandle));
  266.     }
  267.     if (whichControl == self->mTickMarksHandle) {
  268.         HandleControlClick (self->mTickMarksHandle, where, curEvent.modifiers, nil);
  269.         SetTickMarks (self->mData, GetControlValue (self->mTickMarksHandle));
  270.     }
  271.     if (whichControl == self->mNonDirectionalHandle) {
  272.         HandleControlClick (self->mNonDirectionalHandle, where, curEvent.modifiers, nil);
  273.         SetNonDirectional (self->mData, GetControlValue (self->mNonDirectionalHandle));
  274.     }
  275.     if (whichControl == self->mLittleArrowsHandle) {
  276.         HandleControlClick (self->mLittleArrowsHandle, where, curEvent.modifiers, nil);
  277.         SetLittleArrows (self->mData, GetControlValue (self->mLittleArrowsHandle));
  278.     }
  279.     if (whichControl == self->mSpinnerHandle) {
  280.         HandleControlClick (self->mSpinnerHandle, where, curEvent.modifiers, nil);
  281.         SetSpinner (self->mData, GetControlValue (self->mSpinnerHandle));
  282.     }
  283.     if (whichControl == self->mVolumeControlHandle) {
  284.         HandleControlClick (self->mVolumeControlHandle, where, curEvent.modifiers, nil);
  285.         SetVolumeControl (self->mData, GetControlValue (self->mVolumeControlHandle));
  286.     }
  287.     if (whichControl == self->mJimSSliderHandle) {
  288.         HandleControlClick (self->mJimSSliderHandle, where, curEvent.modifiers, nil);
  289.         SetJimSSlider (self->mData, GetControlValue (self->mJimSSliderHandle));
  290.     }
  291. }
  292.  
  293. //----------
  294. void    Bars_DataChanged (
  295.     Bars*        self,
  296.     long            inDataID)
  297. {
  298.     if (inDataID == idBars) {
  299.         SetControlValue (self->mBarsHandle, GetBars (self->mData));
  300.         SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  301.     }
  302.     if (inDataID == idStandard2) {
  303.         SetControlValue (self->mStandard4Handle, GetStandard2 (self->mData));
  304.     }
  305.     if (inDataID == idGraphic2) {
  306.         SetControlValue (self->mGraphic4Handle, GetGraphic2 (self->mData));
  307.     }
  308.     if (inDataID == idSlider) {
  309.         SetControlValue (self->mSliderHandle, GetSlider (self->mData));
  310.     }
  311.     if (inDataID == idTickMarks) {
  312.         SetControlValue (self->mTickMarksHandle, GetTickMarks (self->mData));
  313.     }
  314.     if (inDataID == idNonDirectional) {
  315.         SetControlValue (self->mNonDirectionalHandle, GetNonDirectional (self->mData));
  316.     }
  317.     if (inDataID == idLittleArrows) {
  318.         SetControlValue (self->mLittleArrowsHandle, GetLittleArrows (self->mData));
  319.     }
  320.     if (inDataID == idSpinner) {
  321.         SetControlValue (self->mSpinnerHandle, GetSpinner (self->mData));
  322.     }
  323.     if (inDataID == idVolumeControl) {
  324.         SetControlValue (self->mVolumeControlHandle, GetVolumeControl (self->mData));
  325.     }
  326.     if (inDataID == idJimSSlider) {
  327.         SetControlValue (self->mJimSSliderHandle, GetJimSSlider (self->mData));
  328.     }
  329.     if (inDataID == idStandard3) {
  330.         SetControlValue (self->mStandard5Handle, GetStandard3 (self->mData));
  331.     }
  332.     if (inDataID == idIndeterminate) {
  333.         SetControlValue (self->mIndeterminateHandle, GetIndeterminate (self->mData));
  334.     }
  335.     if (inDataID == idChasingArrows) {
  336.         SetControlValue (self->mChasingArrowsHandle, GetChasingArrows (self->mData));
  337.     }
  338.     if (inDataID == idRectangle) {
  339.         SetControlValue (self->mRectangleHandle, GetRectangle (self->mData));
  340.     }
  341.     if (inDataID == idRoundRect) {
  342.         SetControlValue (self->mRoundRectHandle, GetRoundRect (self->mData));
  343.     }
  344.     if (inDataID == idBarberPole) {
  345.         SetControlValue (self->mBarberPoleHandle, GetBarberPole (self->mData));
  346.     }
  347.     if (inDataID == idRoundBarber) {
  348.         SetControlValue (self->mRoundBarberHandle, GetRoundBarber (self->mData));
  349.     }
  350. }
  351.  
  352. /*----------*/
  353. void    Bars_MouseIn (
  354.     Bars*        self,
  355.     Point            where,
  356.     short            modifiers)
  357. {
  358.     Rect        bounds;
  359.  
  360. }
  361.  
  362. //----------
  363. void    Bars_ExitCurField (
  364.     Bars*        self)
  365. {
  366.     ControlHandle    focus;
  367.  
  368.     GetKeyboardFocus (self->super.mWindow, &focus);
  369.  
  370.     if (focus == nil) {
  371.         // nothing to exit
  372.  
  373.     }
  374. }
  375.  
  376. /*----------*/
  377. void    Bars_TypeIn (
  378.     Bars*        self,
  379.     char            ch)
  380. {
  381.     ControlHandle    focus;
  382.     short            keyCode;
  383.  
  384.     GetKeyboardFocus (self->super.mWindow, &focus);
  385.  
  386.     if ((ch == charEnter)
  387.     ||  (ch == charReturn)) {
  388.         Bars_ExitCurField (self);    // Dispatch
  389.     } else if (ch == charEsc) {
  390.     } else if (ch == charTab) {
  391.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  392.     } else if (focus != nil) {
  393.         keyCode = curEvent.message & keyCodeMask;
  394.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  395.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  396.     } else {
  397.         SysBeep (1);
  398.     }
  399. }
  400.  
  401. /*----------*/
  402. void    Bars_Resize (
  403.     Bars*        self)
  404. {
  405.     /* application-specific code to resize items in window */
  406. }
  407.  
  408. /*----------*/
  409. void    Bars_Scroll (
  410.     Bars*        self,
  411.     short            newValue,
  412.     short            oldValue)
  413. {
  414.     /* application-specific code to scroll window */
  415.     if (gWhichScroll == self->super.vScroll) {
  416.     } else {    // horizontal
  417.     }
  418. }
  419.  
  420. //----------
  421. void    DoUndo (
  422.     Bars*        self)
  423. {
  424. } // DoUndo
  425.  
  426. //----------
  427. void    DoCut (
  428.     Bars*        self)
  429. {
  430.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  431.  
  432.     if (curTE != nil) {
  433.         TECut (curTE);
  434.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  435.         scrapDirty = true;
  436.     }
  437. } // DoCut
  438.  
  439. //----------
  440. void    DoCopy (
  441.     Bars*        self)
  442. {
  443.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  444.  
  445.     if (curTE != nil) {
  446.         TECopy (curTE);
  447.         scrapDirty = true;
  448.     }
  449. } // DoCopy
  450.  
  451. //----------
  452. void    DoPaste (
  453.     Bars*        self)
  454. {
  455.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  456.  
  457.     if (curTE != nil) {
  458.         TEPaste (curTE);
  459.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  460.     }
  461. } // DoPaste
  462.  
  463. //----------
  464. void    DoClear (
  465.     Bars*        self)
  466. {
  467.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  468.  
  469.     if (curTE != nil) {
  470.         TEDelete (curTE);
  471.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  472.     }
  473. } // DoClear
  474.  
  475. //----------
  476. void    DoSelectAll (
  477.     Bars*        self)
  478. {
  479.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  480.  
  481.     if (curTE != nil) {
  482.         TESetSelect (0, 32767, curTE);
  483.     }
  484. } // DoSelectAll
  485.  
  486. //----------
  487. void    DoShowClipboard (
  488.     Bars*        self)
  489. {
  490. } // DoShowClipboard
  491.  
  492. //----------
  493. Boolean        Bars_DoCommand (
  494.     Bars*        self,
  495.     long            inCommand)
  496. {
  497.     Boolean        result = true;
  498.  
  499.     switch (inCommand) {
  500.         case cmdUndo:
  501.                 DoUndo (self);
  502.             break;
  503.         case cmdCut:
  504.                 DoCut (self);
  505.             break;
  506.         case cmdCopy:
  507.                 DoCopy (self);
  508.             break;
  509.         case cmdPaste:
  510.                 DoPaste (self);
  511.             break;
  512.         case cmdClear:
  513.                 DoClear (self);
  514.             break;
  515.         case cmdSelectAll:
  516.                 DoSelectAll (self);
  517.             break;
  518.         case cmdShowClipboard:
  519.                 DoShowClipboard (self);
  520.             break;
  521.  
  522.         default:
  523.                 result = false;
  524.     } // switch
  525.  
  526.     return result;
  527. }
  528.